-
MGLSource
is an abstract base class for map content sources. A map content source supplies content to be shown on the map. A source is added to anMGLStyle
object along with anMGLForegroundStyleLayer
object. The foreground style layer defines the appearance of any content supplied by the source.Each source defined by the style JSON file is represented at runtime by an
MGLSource
object that you can use to refine the map’s content. You can also add and remove sources dynamically using methods such as-[MGLStyle addSource:]
and-[MGLStyle sourceWithIdentifier:]
.Create instances of
See moreMGLShapeSource
,MGLComputedShapeSource
,MGLImageSource
, and the concrete subclasses ofMGLTileSource
(MGLVectorTileSource
andMGLRasterTileSource
) in order to useMGLSource
’s properties and methods. Do not create instances ofMGLSource
directly, and do not create your own subclasses of this class.Declaration
Objective-C
@interface MGLSource : NSObject
Swift
class MGLSource : NSObject
-
MGLShapeSource
is a map content source that supplies vector shapes to be shown on the map. The shapes may be instances ofMGLShape
orMGLFeature
, or they may be defined by local or external GeoJSON code. A shape source is added to anMGLStyle
object along with anMGLVectorStyleLayer
object. The vector style layer defines the appearance of any content supplied by the shape source. You can update a shape source by setting itsshape
orURL
property.MGLShapeSource
is optimized for data sets that change dynamically and fit completely in memory. For large data sets that do not fit completely in memory, use theMGLComputedShapeSource
orMGLVectorTileSource
class.Each
geojson
source defined by the style JSON file is represented at runtime by anMGLShapeSource
object that you can use to refine the map’s content and initialize new style layers. You can also add and remove sources dynamically using methods such as-[MGLStyle addSource:]
and-[MGLStyle sourceWithIdentifier:]
.Any vector style layer initialized with a shape source should have a
nil
value in itssourceLayerIdentifier
property.Example
var coordinates: [CLLocationCoordinate2D] = [ CLLocationCoordinate2D(latitude: 37.77, longitude: -122.42), CLLocationCoordinate2D(latitude: 38.91, longitude: -77.04), ] let polyline = MGLPolylineFeature(coordinates: &coordinates, count: UInt(coordinates.count)) let source = MGLShapeSource(identifier: "lines", features: [polyline], options: nil) mapView.style?.addSource(source)
Related examples
See the Cluster point data, Use images to cluster point data, and Add live data examples to learn how to add data to your map using this
See moreMGLSource
object. -
MGLComputedShapeSource
is a map content source that supplies vector shapes, one tile at a time, to be shown on the map on demand. You implement a class conforming to theMGLComputedShapeSourceDataSource
protocol that returns instances ofMGLShape
orMGLFeature
, then add a computed shape source to anMGLStyle
object along with anMGLVectorStyleLayer
object. The vector style layer defines the appearance of any content supplied by the computed shape source.MGLComputedShapeSource
is similar toMGLShapeSource
but is optimized for data sets that change dynamically or are too large to fit completely in memory. It is also useful for data that is divided into tiles in a format other than Mapbox Vector Tiles. For GeoJSON data, use theMGLShapeSource
class. For static tiles or Mapbox Vector Tiles, use theMGLVectorTileSource
class.You can add and remove sources dynamically using methods such as
See more-[MGLStyle addSource:]
and-[MGLStyle sourceWithIdentifier:]
. This class cannot be represented in a style JSON file; you must add it ot the style at runtime. -
MGLTileSource
is a map content source that supplies map tiles to be shown on the map. The location of and metadata about the tiles are defined either by an option dictionary or by an external file that conforms to the TileJSON specification. A tile source is added to anMGLStyle
object along with one or moreMGLRasterStyleLayer
orMGLVectorStyleLayer
objects. Use a style layer to control the appearance of content supplied by the tile source.A tile source is also known as a tile set. To learn about the structure of a Mapbox-hosted tile set, view it in Mapbox Studio’s Tilesets editor.
Create instances of
See moreMGLRasterTileSource
andMGLVectorTileSource
in order to useMGLTileSource
‘s properties and methods. Do not create instances ofMGLTileSource
directly, and do not create your own subclasses of this class. -
MGLRasterTileSource
is a map content source that supplies raster image tiles to be shown on the map. The location of and metadata about the tiles are defined either by an option dictionary or by an external file that conforms to the TileJSON specification. A raster tile source is added to anMGLStyle
object along with one or moreMGLRasterStyleLayer
objects. Use a raster style layer to control the appearance of content supplied by the raster tile source.Each
raster
source defined by the style JSON file is represented at runtime by anMGLRasterTileSource
object that you can use to initialize new style layers. You can also add and remove sources dynamically using methods such as-[MGLStyle addSource:]
and-[MGLStyle sourceWithIdentifier:]
.Example
let source = MGLRasterTileSource(identifier: "clouds", tileURLTemplates: ["https://example.com/raster-tiles/{z}/{x}/{y}.png"], options: [ .minimumZoomLevel: 9, .maximumZoomLevel: 16, .tileSize: 512, .attributionInfos: [ MGLAttributionInfo(title: NSAttributedString(string: "© Mapbox"), url: URL(string: "https://mapbox.com")) ] ]) mapView.style?.addSource(source)
Related examples
See the Add raster imagery example to learn how to add a
See moreMGLRasterStyleLayer
to your map using anMGLRasterTileSource
.Declaration
Objective-C
@interface MGLRasterTileSource : MGLTileSource
Swift
class MGLRasterTileSource : MGLTileSource
-
MGLRasterDEMSource
is a map content source that supplies rasterized digital elevation model (DEM) tiles to be shown on the map. The location of and metadata about the tiles are defined either by an option dictionary or by an external file that conforms to the TileJSON specification. A raster DEM source is added to anMGLStyle
object along with one or moreMGLHillshadeStyleLayer
objects. Use a hillshade style layer to control the appearance of content supplied by the raster DEM source.Each
raster-dem
source defined by the style JSON file is represented at runtime by anMGLRasterDEMSource
object that you can use to initialize new style layers. You can also add and remove sources dynamically using methods such as-[MGLStyle addSource:]
and-[MGLStyle sourceWithIdentifier:]
.Currently, raster DEM sources only support the format used by Mapbox Terrain-RGB.
Example
let terrainRGBURL = URL(string: "maptiler://sources/terrain-rgb")! let source = MGLRasterDEMSource(identifier: "hills", configurationURL: terrainRGBURL) mapView.style?.addSource(source)
Declaration
Objective-C
@interface MGLRasterDEMSource : MGLRasterTileSource
Swift
class MGLRasterDEMSource : MGLRasterTileSource
-
MGLVectorTileSource
is a map content source that supplies tiled vector data in Mapbox Vector Tile format to be shown on the map. The location of and metadata about the tiles are defined either by an option dictionary or by an external file that conforms to the TileJSON specification. A vector tile source is added to anMGLStyle
object along with one or moreMGLVectorStyleLayer
objects. A vector style layer defines the appearance of any content supplied by the vector tile source.MGLVectorTileSource
is optimized for data sets that are too large to fit completely in memory, such as vector tile sets or data sets managed in Mapbox Studio. For GeoJSON data, use theMGLShapeSource
class. For tiled data that changes dynamically, theMGLComputedShapeSource
class may be a suitable alternative.Each
vector
source defined by the style JSON file is represented at runtime by anMGLVectorTileSource
object that you can use to initialize new style layers. You can also add and remove sources dynamically using methods such as-[MGLStyle addSource:]
and-[MGLStyle sourceWithIdentifier:]
.Within each vector tile, each geometric coordinate must lie between −1 × extent and (extent × 2) − 1, inclusive. Any vector style layer initialized with a vector tile source must have a non-
nil
value in itssourceLayerIdentifier
property.Commonly used vector tile sources include Mapbox Streets, Mapbox Terrain, and Mapbox Traffic.
Example
let source = MGLVectorTileSource(identifier: "pois", tileURLTemplates: ["https://example.com/vector-tiles/{z}/{x}/{y}.mvt"], options: [ .minimumZoomLevel: 9, .maximumZoomLevel: 16, .attributionInfos: [ MGLAttributionInfo(title: NSAttributedString(string: "© Mapbox"), url: URL(string: "https://mapbox.com")) ] ]) mapView.style?.addSource(source)
Related examples
See the Data-driven circles example to learn how to add data to your map using an
See moreMGLVectorTileSource
object.Declaration
Objective-C
@interface MGLVectorTileSource : MGLTileSource
Swift
class MGLVectorTileSource : MGLTileSource
-
MGLImageSource
is a content source that is used for a georeferenced raster image to be shown on the map. The georeferenced image scales and rotates as the user zooms and rotates the map. Images may also be used as icons or patterns in a style layer. To register an image for use as an icon or pattern, use the-[MGLStyle setImage:forName:]
method. To configure a point annotation’s image, use theMGLAnnotationImage
class.The geographic location of the raster image content, supplied with
MGLCoordinateQuad
, can be non-axis aligned.MGLImageSource
supports raster content fromNSURL
,NSImage
(macOS), orUIImage
(iOS). An image source is added to anMGLStyle
object along with one or moreMGLRasterStyleLayer
objects. Use a raster style layer to control the appearance of content supplied by the image source.Each
image
source defined by the style JSON file is represented at runtime by anMGLImageSource
object that you can use to initialize new style layers. You can also add and remove sources dynamically using methods such as-[MGLStyle addSource:]
and-[MGLStyle sourceWithIdentifier:]
.Example
let coordinates = MGLCoordinateQuad( topLeft: CLLocationCoordinate2D(latitude: 46.437, longitude: -80.425), bottomLeft: CLLocationCoordinate2D(latitude: 37.936, longitude: -80.425), bottomRight: CLLocationCoordinate2D(latitude: 37.936, longitude: -71.516), topRight: CLLocationCoordinate2D(latitude: 46.437, longitude: -71.516)) let source = MGLImageSource(identifier: "radar", coordinateQuad: coordinates, url: URL(string: "https://maplibre.org/maplibre-gl-js-docs/assets/radar.gif")!) mapView.style?.addSource(source)
Related examples
See the Add an image example to learn how to add an image to your map using
See moreMGLImageSource
.